package com.mef.smsplat.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.cqcis.base.orm.jdbc.BaseJdbcDao;
import com.mef.smsplat.dao.base.BaseSpringJdbcDao;
import com.mef.smsplat.dao.base.DataGridModel;
import com.mef.smsplat.dao.base.Page;
import com.mef.smsplat.domain.SysAdminInfoDomain;

@Repository
public class SysAdminInfoDao extends BaseSpringJdbcDao<SysAdminInfoDomain, String> {
	
	/**
	 * 根据用户名和密码查询管理员信息
	 * @param username
	 * @param password
	 * @return
	 */
	public SysAdminInfoDomain query(String username,String password){
		String sql="select * from sys_admin_Info t where t.admin_name=? and t.admin_password=?";
		List<SysAdminInfoDomain> list=super.query(sql, new Object[]{username,password});
		if(list.size()>0)
			return list.get(0);
		return null;
	}
	
	/**
	 * 根据用户名和id查询账号是否唯一
	 * @param name
	 * @param id
	 * @return
	 */
	public boolean queryByNameAndId(String name,String id){
		String sql="select * from sys_admin_Info t where t.admin_name=? and t.sys_admin_id!=?";
		List<SysAdminInfoDomain> list=super.query(sql, new Object[]{name,id});
		if(list.size()>0)
			return false;
		return true;
	}
	
	/**
	 * 根据用户名分页查询管理员信息
	 * @param adminName
	 * @param dgm
	 * @return
	 */
	public Page query(String adminName,DataGridModel dgm){
		List<Object> params=new ArrayList<Object>();
		StringBuilder sql=new StringBuilder();
		sql.append("select * from sys_admin_Info where 1=1");
		if(adminName!=null&&!"".equals(adminName)){
			sql.append(" and admin_name like ?");
			params.add("%"+adminName+"%");
		}
		return super.queryObjByPage(sql.toString(), dgm.getRows(), dgm.getPage(), params);
	}

	@Override
	public BaseJdbcDao getDaoClass() {
		return this;
	}

	@Override
	public Class getEntityClass() {
		return SysAdminInfoDomain.class;
	}

}
